<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>手写assign()的方法：</title>
</head>
<body>
  <script>
    //手写assign()的方法：
    function myAssign(target, source){
      for(const key in source){
        target[key]= source[key]
      }
      return target;
    }
    let t = {x:1,y:2};
    let s = {name: "张强",x:200}

    let newObj = myAssign(t, s)
    console.log(t); // {x: 200, y: 2, name: '张强'}
    console.log(s); // {name: "张强",x:200}
    console.log(newObj); // {x: 200, y: 2, name: '张强'}


  </script>
</body>
</html>